/**
 * Import libraries that are needed for the game
 */
import java.awt.Point;
import java.util.Random;

/**
 * This class creates the planets in the universe
 * 
 * @author Eric
 * @version 1.0
 *
 */

@SuppressWarnings("serial")
public class Planet implements java.io.Serializable{
	/**
	 * Field news.
	 */
	/**
	 * Field resources.
	 */
	/**
	 * Field techLevel.
	 */
	private int techLevel, resources, news;

	/**
	 * Field market.
	 */
	private MarketPlace market;

	/**
	 * Field techArray.
	 */
	public final String[] techArray = new String[]
			{
			"Pre-Agriculture",

			"Agriculture",

			"Medieval",

			"Renaissance",

			"Early Industrial",

			"Industrial",

			"Post-Industrial",

			"Hi-Tech"
		};

	/**
	 * Field resArray.
	 */
	public final String[] resArray = new String[]
			{
			"NOSPECIALRESOURCES",

			"MINERALRICH",

			"MINERALPOOR",

			"DESERT",

			"LOTSOFWATER",

			"RICHSOIL",

			"POORSOIL",

			"RICHFAUNA",

			"LIFELESS",

			"WEIRDMUSHROOMS",

			"LOTSOFHERBS",

			"ARTISTIC",

			"WARLIKE",
		};

	/**
	 * Field point.
	 */
	private Point point;

	/**
	 * Field name.
	 */
	private String name;
	
	/**
	 * Field randRes.
	 */
	/**
	 * Field randTech.
	 */
	private Random randTech, randRes;

	/**
	 * Creates the default planet
	 */
	
	public Planet(){
		market = null;
	}
	
	/**
	 * This method makes a planet with a specific tech level,
	 * position, name, and resources
	 * @param name The name of the planet
	 */
	
	public Planet(String name){
		// Lost of precision in cast is acceptable in this class
		// because it does not affect the correctness of the game
		final int x=(int) (Math.random() * 280) + 1; // $codepro.audit.disable lossOfPrecisionInCast
		final int y=(int) (Math.random() * 179) + 1; // $codepro.audit.disable lossOfPrecisionInCast
		randTech = new Random();
		randRes = new Random();
		techLevel = randTech.nextInt(8);
		resources = randRes.nextInt(13);
		news=-1;
		
		this.name=name;
		point = new Point(x, y);
		market = new MarketPlace(this);
	}
	
	/**
	 * Constructor for Planet.
	 * @param name String
	 * @param location Point
	 */
	public Planet(String name, Point location) {
		// TODO Auto-generated constructor stub
		randTech = new Random();
		randRes = new Random();
		techLevel = randTech.nextInt(8);
		resources = randRes.nextInt(13);
		news=-1;
		
		this.name=name;
		point = new Point(location.x, location.y);
		market = new MarketPlace(this);
	}

	/**
	 * Gets the point of the planet
	
	 * @return The planet's point */
	
	public Point getLocation(){
		return point;
	}
	
	/**
	 * Sets the location of the planet so it can move
	 * @param x The x location in the universe
	 * @param y The y location in the universe
	 */
	
	public void setLocation(int x, int y){
		point.setLocation(x, y);
	}
	
	/**
	 * Gets the name of the planet
	
	 * @return The planet's name */
	
	public String getName(){
		return name;
	}
	
	/**
	 * Sets the name of the planet
	 * @param name The planet's name
	 */
	
	public void setName(String name){
		this.name = name;
	}
	
	/**
	 * Gets the tech level of the planet
	
	 * @return The planet's tech level */
	
	public int getTech(){
		return techLevel;
	}
	
	/**
	 * Sets the tech level of the planet
	 * @param tech The planet's tech level
	 */
	
	public void setTech(int tech){
		techLevel = tech;
	}
	
	/**
	 * Gets the resources of the planet
	
	 * @return The planet's resources */
	
	public int getResources(){
		return resources;
	}
	
	/**
	 * Sets the resources of the planet
	 * @param resources The planet's resources
	 */
	
	public void setResources(int resources){
		this.resources=resources;
	}
	
	/**
	 * Information of the planet
	
	 * @return The planet's information */
	
	@Override
	public String toString(){
		String res="";
		res+=name + " " + techArray[techLevel] + " " +
		resArray[resources] + " (" + point.x + "," + point.y + ")";
		return res;
	}
	
	/**
	 * getter that returns the appropriate resource in the resource array
	 * 
	 * @param x The index of the current resource
	
	 * @return The appropriate resource for this planet */
	public String getResourcesAt(int x) {
		return resArray[x];
	}
	
	/**
	 * getter that returns the appropriate tech level in the tech level array
	 * 
	 * @param x The index of the current tech level
	
	 * @return The appropriate tech level for this planet */
	public String getTechLevel(int x) {
		return techArray[x];
	}
	
	/**
	 * getter that returns the market place of the planet
	 * 
	
	 * @return The marketplace of the planet */
	public MarketPlace getMarket(){
		return market;
	}
	
	/**
	 * Helper method that sets the markerplace values
	 * 
	 * @param marketPlace The marketplace of all the goods
	 */
	public void setMarket(MarketPlace marketPlace) {
		// TODO Auto-generated method stub
		this.market=marketPlace;
	}
	
	/**
	 * getter that returns the location of the planet
	
	 * @return The position of the planet in the universe */
	public String getLocationString() {
		// TODO Auto-generated method stub
		return "new Point(" + point.x + "," + point.y + "),";
	}

	/**
	 * Method setNews.
	 * @param i int
	 */
	public void setNews(int i) {
		// TODO Auto-generated method stub
		news=i;
	}

	/**
	 * Method getNews.
	 * @return int
	 */
	public int getNews() {
		// TODO Auto-generated method stub
		return news;
	}
	
	
}